// hospital/pages/doctorList/doctorList.js
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    baseUrl: app.globalData.path,
    doctorList: []
  },


  getDoctorList() {

    var url = app.globalData.url + "doctor/listDoctors",
      that = this,
      baseUrl = this.data.baseUrl;
    wx.showLoading({
      title: '',
    })
    app.wxRequest(url, {}, res => {
        console.log(res);
        if (res.flag) {
          wx.hideLoading()
          var datas = res.data
          that.setData({
            doctorList: datas
          })
          console.log(that.data);
        }
      },
      err => {
        console.log(err);
      })

  },

  toDetail(e) {
    console.log(e);
    var doctor = e.currentTarget.dataset.doctor
    wx.navigateTo({
      url: '/doctor/pages/doctorDetail/doctorDetail?doctor=' + JSON.stringify(doctor),
    })
  },


  avatarError(e) {
    console.log(e);
    var index = e.currentTarget.dataset.imgindex,
      list = this.data.doctorList,
      src = '/img/userImg.jpg';
    list[index].doctorPic = src
    this.setData({
      doctorList: list
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.getDoctorList()
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})